unit MainForm;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Objects, FMX.Layouts, System.Actions, FMX.ActnList, FMX.TabControl,
  FMX.Menus;

type
  TfrmMain = class(TForm)
    ToolBar1: TToolBar;
    btnExit: TButton;
    Image1: TImage;
    btnPrint: TButton;
    Image2: TImage;
    btnCancel: TButton;
    Image3: TImage;
    btnOK: TButton;
    Image4: TImage;
    btnErase: TButton;
    Image5: TImage;
    btnModify: TButton;
    Image6: TImage;
    btnAdd: TButton;
    Image7: TImage;
    btnSettings: TButton;
    Image8: TImage;
    btnInfo: TButton;
    Image9: TImage;
    StatusBar1: TStatusBar;
    LayoutMain: TLayout;
    Actions: TActionList;
    btnExitAction: TAction;
    Action2: TAction;
    pmModify: TPopupMenu;
    pmErase: TPopupMenu;
    popInfo: TPopupMenu;
    pmAdd: TPopupMenu;
    btnAddAction: TAction;
    btnModifyAction: TAction;
    btnEraseAction: TAction;
    miAlunno: TMenuItem;
    miParente: TMenuItem;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnExitActionExecute(Sender: TObject);
    procedure btnAddActionExecute(Sender: TObject);
    procedure btnModifyActionExecute(Sender: TObject);
    procedure btnEraseActionExecute(Sender: TObject);
  private
    procedure VisualizzaPopUp(Bottone: TButton; menu: TPopupMenu);
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

uses
  LoginForm, DatiGeneraliForm;

var
  NoLogin : Boolean;
  FormAttiva : TForm;

{$R *.fmx}

procedure TfrmMain.btnAddActionExecute(Sender: TObject);
begin
  VisualizzaPopUp(btnAdd, pmAdd);
end;

procedure TfrmMain.btnEraseActionExecute(Sender: TObject);
begin
  VisualizzaPopUp(btnErase, pmErase);
end;

procedure TfrmMain.btnExitActionExecute(Sender: TObject);
begin
  if FormAttiva = frmDatiGenerali then begin
    close;
  end;

end;

procedure TfrmMain.btnModifyActionExecute(Sender: TObject);
begin
  VisualizzaPopUp(btnModify, pmModify);
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  NoLogin := FALSE;
  frmLogin := TfrmLogin.create(nil);
  if frmLogin.ShowModal <> mrOK then
    NoLogin := TRUE;
  frmLogin.Free;
end;

procedure TfrmMain.FormShow(Sender: TObject);
begin
  if NoLogin then
    close
  else begin
    frmDatiGenerali := TfrmDatiGenerali.Create(LayoutMain);
    frmDatiGenerali.Children[0].Parent := LayoutMain;
    FormAttiva :=  frmDatiGenerali;
  end;

end;

procedure TfrmMain.VisualizzaPopUp(Bottone: TButton; menu: TPopupMenu);
begin
  menu.Popup(Bottone.Position.X + FrmMain.Left - 30, Bottone.Position.Y + FrmMain.Top + 93);
end;

end.
